import 'package:fluro_decorate/src/navigator_util.dart';
import 'package:flutter/material.dart';

///
/// @ProjectName:    fluro_decorate
/// @Package:
/// @ClassName:      NavigatorObserverDecorate
/// @Description:
/// 导航栈的变化监听,注册路由监听器:
///  navigatorObservers: [//这个监听器是个集合，可根据不同需求对路由做不同的设置
///    NavigatorObserverDecorate(),
///  ],
/// @Author:         WTT
/// @CreateDate:     2021/11/1 4:37 下午
class NavigatorObserverDecorate extends NavigatorObserver {
  /// 进入路由
  @override
  void didPush(Route<dynamic> route, Route<dynamic> previousRoute) {
    super.didPush(route, previousRoute);

    var previousName = '';
    if (previousRoute == null) {
      previousName = 'null';
    } else {
      previousName = previousRoute.settings.name;
    }

    print('NavigatorObserverDecorate-Current:' +
        route.settings.name +
        '  Previous:' +
        previousName);
  }

  /// 弹出路由
  @override
  void didPop(Route<dynamic> route, Route<dynamic> previousRoute) {
    super.didPop(route, previousRoute);
    var previousName = '';
    if (previousRoute == null) {
      previousName = 'null';
    } else {
      previousName = previousRoute.settings.name;
    }

    print('NavigatorObserverDecorate--Current:' +
        route.settings.name +
        '  Previous:' +
        previousName);

    NavigatorUtil.checkRouteCacheStack(route.settings.name);
  }

  /// 用户势控制路由
  @override
  void didStartUserGesture(Route<dynamic> route, Route<dynamic> previousRoute) {
    super.didStartUserGesture(route, previousRoute);
  }

  ///用户手势不再控制路由，与上一个相配
  @override
  void didStopUserGesture() {
    super.didStopUserGesture();
  }

  /// 用新路由替换旧路由
  @override
  void didReplace({Route<dynamic> newRoute, Route<dynamic> oldRoute}) {
    super.didReplace(newRoute: newRoute, oldRoute: oldRoute);
  }

  /// 删除路由
  @override
  void didRemove(Route<dynamic> route, Route<dynamic> previousRoute) {
    super.didRemove(route, previousRoute);
  }
}
